import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Language } from "../../../../../extend/language/Language";
import { ItemBgPanel } from "./ItemBgPanel";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { BrowerUtil } from "../../../../../com/gengine/utils/BrowerUtil";
import { SpecialGiftGetWindow } from "./SpecialGiftGetWindow";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { SpecialGiftInfo } from "../../../model/SpecialGiftInfo";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
//class SpecialGiftItem
    
    export  class SpecialGiftItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            this._bgImg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            this._bgImg.width = this.width;
            this._bgImg.height = this.height;
            addChild(this._bgImg);
            this._titleBg = ResouceConst.getScaleBitmap(ImagesConst.RbListHeader);
            this._titleBg.width = this.width + 3;
            this._titleBg.y = -3;
            addChild(this._titleBg);
            this._titleTxt = new Object /* flash.text.TextField */();
            this._titleTxt.defaultTextFormat = new GTextFormat("", 12, 16711935, true);
            this._titleTxt.filters = [FilterConst.nameGlowFilter];
            this._titleTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._titleTxt.textColor = 16711935;
            this._titleTxt.selectable = false;
            this._titleTxt.width = this.width;
            this._titleTxt.y = 5;
            this._titleTxt.x = this.width / 2;
            this._titleTxt.text = Language.getString(25000) + "：2012-02-24 09: 23 -- 2012-02-24 10: 23";
            addChild(this._titleTxt);
            this._itemBg = ResouceConst.getScaleBitmap(ImagesConst.PackItemBg);
            this._itemBg.width = 66;
            this._itemBg.height = 66;
            this._itemBg.x = 50;
            this._itemBg.y = 54;
            addChild(this._itemBg);
            this._itemIcon = new Object /* flash.display.Bitmap */();
            this._itemIcon.x = this._itemBg.x + 3;
            this._itemIcon.y = this._itemBg.y + 3;
            addChild(this._itemIcon);
            this._name = new Object /* flash.text.TextField */();
            this._name.filters = [FilterConst.nameGlowFilter];
            this._name.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._name.textColor = 16711935;
            this._name.selectable = false;
            this._name.width = 90;
            this._name.y = this._itemBg.y - 20;
            this._name.x = this._itemBg.x + this._itemBg.width / 2;
            this._name.text = "xxxxxx";
            addChild(this._name);
            this._itemList = new ItemBgPanel(16, 8, 40, 40);
            this._itemList.x = 182;
            this._itemList.y = 42;
            addChild(this._itemList);
            this._optBtn1 = new GButton();
            this._optBtn1.styleName = "ButtonSpecial";
            this._optBtn1.setSize(86, 22);
            this._optBtn1.label = Language.getString(25001);
            this._optBtn1.textField.filters = [FilterConst.nameGlowFilter];
            this._optBtn1.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtn1ClickHandler);
            this._optBtn1.x = 542;
            this._optBtn1.y = 50;
            addChild(this._optBtn1);
            this._optBtn2 = new GButton();
            this._optBtn2.styleName = "ButtonSpecial";
            this._optBtn2.setSize(86, 22);
            this._optBtn2.label = Language.getString(25002);
            this._optBtn2.textField.filters = [FilterConst.nameGlowFilter];
            this._optBtn2.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtn2ClickHandler);
            this._optBtn2.x = this._optBtn1.x;
            this._optBtn2.y = 90;
            addChild(this._optBtn2);
            return;
        }

        /* internal  */onOptBtn1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info && this._info.giftFlagUrl) 
            {
                BrowerUtil.getUrl(this._info.giftFlagUrl);
            }
            return;
        }

        /* internal  */onOptBtn2ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                SpecialGiftGetWindow.instance.updateData(this._info);
                SpecialGiftGetWindow.instance.show();
            }
            return;
        }

        /* internal  */onIconLoadedHandler(arg1: ImageInfo): void
        {
            if (this._itemIcon != null) 
            {
                this._itemIcon.bitmapData = arg1.bitmapData;
            }
            return;
        }

        public updateData(arg1: SpecialGiftInfo): void
        {
            this.dispose();
            this._info = arg1;
            this._titleTxt.htmlText = HTMLUtil.addColor(Language.getString(25000) + "：", "#ffff00") + HTMLUtil.addColor(this._info.getGiftTime, "#F13635");
            this._name.htmlText = HTMLUtil.addColor(arg1.itemName, "#ff00ff");
            this._itemList.updateData(arg1.rewardItems);
            LoaderManager.instance.load(arg1.itemUrl, this.onIconLoadedHandler);
            if (this._info.activeNumEnd) 
            {
                this._optBtn2.enabled = false;
            }
            else 
            {
                this._optBtn2.enabled = true;
            }
            if (this._info.giftFlagUrl) 
            {
                if (!this._optBtn1.parent) 
                {
                    addChild(this._optBtn1);
                }
                this._optBtn2.y = 90;
            }
            else 
            {
                if (this._optBtn1.parent) 
                {
                    removeChild(this._optBtn1);
                }
                this._optBtn2.y = 70;
            }
            return;
        }

        public dispose(): void
        {
            this._info = null;
            return;
        }

        public /* override */ get width(): number
        {
            return 675;
        }

        public /* override */ get height(): number
        {
            return 132;
        }

        protected /* var */_info: SpecialGiftInfo;

        protected /* var */_bgImg: ScaleBitmap;

        protected /* var */_titleBg: ScaleBitmap;

        protected /* var */_titleTxt: Object /* flash.text.TextField */;

        protected /* var */_itemBg: Object /* flash.display.Bitmap */;

        protected /* var */_itemIcon: Object /* flash.display.Bitmap */;

        protected /* var */_name: Object /* flash.text.TextField */;

        protected /* var */_itemList: ItemBgPanel;

        protected /* var */_optBtn1: GButton;

        protected /* var */_optBtn2: GButton;
    }
